﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using CMS.BLL;
using CMS.BLL.Entity;

public partial class AdminX_Product_ProductColormain : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        
        //Alert1.HideMessage();
        if (!IsPostBack)
        {
            SetMulLang();
            //ShowMess();
            BindDataToLanguageDropdown();
            BindDataToRepeater(1);

        }
    }

    private void BindDataToLanguageDropdown()
    {
        DataTable dtbLanguage = new DataTable();
        Languages objLanguage = new Languages();
        dtbLanguage = objLanguage.Search();
        ddlLanguage.DataSource = dtbLanguage;
        ddlLanguage.DataValueField = "LanguageID";
        ddlLanguage.DataTextField = "Description";
        ddlLanguage.DataBind();

    }
    private void SetMulLang()
    {
        int nDefaul = Support.GetDefaultLanguage();
        lblLanguage.Text = MultipleLanguage.LBL_LANGUAGE[nDefaul - 1];
        btnAddnew.Text = MultipleLanguage.BTN_ADDNEW[nDefaul - 1];
        
    }

    private void BindDataToRepeater(int CurrentPageIndex)
    {
        ProductColor objColor = new ProductColor();
        DataTable dtbColor = new DataTable();
        dtbColor = objColor.Search();
        RpProductColor.DataSource = dtbColor;
        RpProductColor.DataBind();
        int nDefaultLanguage = Support.GetDefaultLanguage();
        lblTotalRecord.Text = MultipleLanguage.LBL_TOTAL_ITEM[nDefaultLanguage - 1] + dtbColor.Rows.Count + MultipleLanguage.LBL_FOUND[nDefaultLanguage - 1];
        

    }


    //private void ShowMess()
    //{
    //    int nDefaultLanguage = Support.GetDefaultLanguage() - 1;
    //    int nMessage = ConvertData.ConvertToInt(Request.QueryString[Config.MESS_ID]);
    //    lblWarning.Text = MessagesAlert.SEARCH_NO_ITEM[nDefaultLanguage];
    //    switch (nMessage)
    //    {
    //        case 1:
    //            Alert1.ShowMessage(1, MessagesAlert.INSERT_SUCCESSFULL[nDefaultLanguage]);
    //            break;
    //        case 2:
    //            Alert1.ShowMessage(1, MessagesAlert.UPDATE_SUCCESSFUL[nDefaultLanguage]);
    //            break;
    //        default:
    //            Alert1.HideMessage();
    //            break;

    //    }
    //}


    protected void RpProductColor_ItemCommand1(object source, RepeaterCommandEventArgs e)
    {
        int nDefaultLanguage = Support.GetDefaultLanguage() - 1;
        string strCommand = e.CommandName;
        int nID = ConvertData.ConvertToInt(e.CommandArgument);
        ProductColor objColor = new ProductColor();
        switch (strCommand)
        {
            case "Delete":
                int nDelete = objColor.DeleteById(nID);
                //if (nDelete > 0)
                //    Alert1.ShowMessage(1, MessagesAlert.DELETE_SUCCESSFULL[nDefaultLanguage]);
                //else
                //    Alert1.ShowMessage(2, MessagesAlert.DELETE_UNSUCCESSFULL[nDefaultLanguage]);
                BindDataToRepeater(1);
                break;

            case "Edit":
                string sEdit = Config.ROOT + Pages.BackEnds.ADMIN + "?" + Config.PAGE + "=" + Pages.BackEnds.STR_COLOR_ADD + "&" + Config.ACTION + "=" + Config.ACTION_EDIT + "&" + Config.ACTION_ID + "=" + nID;
                Response.Redirect(sEdit);
                break;
        }
    }
    protected void RpProductColor_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        int nDefaultLanguage = Support.GetDefaultLanguage();
        int nCurrentLang = ConvertData.ConvertToInt(ddlLanguage.SelectedValue);
        if ((e.Item.ItemType != ListItemType.Header) && (e.Item.ItemType != ListItemType.Footer))
        {
            Label lblColor = (Label)e.Item.FindControl("lblColor");
            LinkButton lnkEdit = (LinkButton)e.Item.FindControl("lnkEdit");
            LinkButton lnkDelete = (LinkButton)e.Item.FindControl("lnkDelete");
            switch (nCurrentLang)
            {
                case 1:
                    lblColor.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "ColorName1"));
                    break;
                case 2:
                    lblColor.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "ColorName2"));
                    break;
            }

            lnkEdit.CommandArgument = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "ProductColorID"));
            lnkDelete.OnClientClick = Support.CreateConfirmBoxClient(MessagesAlert.DELETE_ALERT[nDefaultLanguage]);
            lnkDelete.CommandArgument = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "ProductColorID"));
        }
    }
    protected void ddlLanguage_SelectedIndexChanged(object sender, EventArgs e)
    {
        BindDataToRepeater(1);
    }
    protected void btnAddnew_Click1(object sender, EventArgs e)
    {
        string sAddNew = Config.ROOT + Pages.BackEnds.ADMIN + "?" + Config.PAGE + "=" + Pages.BackEnds.STR_COLOR_ADD + "&" + Config.ACTION + "=" + Config.ACTION_ADD;
        Response.Redirect(sAddNew);
    }
}